package com.level2app.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Window;
import android.view.WindowManager;

import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;

import com.level2app.R;
import com.level2app.utils.ScreenUtil;

public abstract class BaseCommonBottomDialog<T extends ViewDataBinding> extends Dialog {
    protected T mBinding;
    protected Context mContext;
    public BaseCommonBottomDialog(Context context) {
        super(context, R.style.BottomDialog);
        this.mContext = context;
    }

    @Override
    protected void onStart() {
        super.onStart();
        setWidth();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), getLayoutId(), null, false);
        setContentView(mBinding.getRoot());
        this.getWindow().setGravity(getGravity());
        this.getWindow().setWindowAnimations(getAnimations());
        initView();
    }

    public void setWidth() {
        Window o = getWindow();
        WindowManager.LayoutParams lp = o.getAttributes();
        lp.width = ScreenUtil.getMaxWidth(getContext());
        o.setAttributes(lp);
    }

    protected int getAnimations() {
        return R.style.main_menu_animStyle;
    }

    protected int getGravity() {
        return Gravity.BOTTOM;
    }

    protected abstract void initView();


    protected abstract int getLayoutId();

    @Override
    protected void onStop() {
        super.onStop();
    }
}
